package com.wei.web.middleware.retry.compensate.aspect;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.Optional;

/**
 * @author shihuimiao
 * create time: 5:38 下午
 */
public class RetryContext {

    private static TransmittableThreadLocal<Boolean> retryContextHolder = new TransmittableThreadLocal<>();

    public static void setNotFirst() {
        retryContextHolder.set(false);
    }

    public static Boolean isFirst() {
        return Optional.ofNullable(retryContextHolder.get())
                .orElse(Boolean.TRUE);
    }


    public static void clear() {
        retryContextHolder.remove();
    }


}
